/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pbl_servidor;

import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Asuka
 */

public class Pingar implements Runnable{
private List<Socket> listaSocketsOnline;
private Socket cliente;
private int i;
private PBL_Servidor pbl;

public Pingar(Socket cli, int j, List<Socket> list,PBL_Servidor p){
    this.listaSocketsOnline = list;
    this.cliente = cli;
    this.i = j;
    this.pbl = p;
} 
    @Override
public void run(){
//    while(true){
//        for(int i=0;i<listaSocketsOnline.size();i++){
//            pbl.pingar(listaSocketsOnline.get(i));
//        }
//    }
    while(true){
        try {
          
            DataOutputStream ping = new DataOutputStream(cliente.getOutputStream());
            
            ping.writeUTF("PING:");
            trataPing rcb = new trataPing(cliente.getInputStream(), pbl, cliente, listaSocketsOnline);
            new Thread(rcb).start();
        }  catch (IOException ex) {
            Logger.getLogger(Pingar.class.getName()).log(Level.SEVERE, null, ex);
        }
}
}
//        try {
//            String host = cliente.getInetAddress().getHostAddress();
//            
//                if(InetAddress.getByName(host).isReachable(100000)){
//                    System.out.println("Ainda online: "+ host);
//                }
//                else{
//                    System.out.println("offline: "+ host);
//                }
//            
//        }   catch (UnknownHostException ex) {
//            Logger.getLogger(Pingar.class.getName()).log(Level.SEVERE, null, ex);
//        }
//            catch (IOException ex) {
//                Logger.getLogger(Pingar.class.getName()).log(Level.SEVERE, null, ex);
//            }
//}
}
